package com.gem.springbootdemo.control;

import com.gem.springbootdemo.entity.Goods;
import com.gem.springbootdemo.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/goods")
public class GoodControl {
    @Autowired
    private GoodsService goodsService;

    @RequestMapping("/index")
    public String  index(Model model) throws Exception{
        List<Goods> goodsList=goodsService.getAllGoods();
        model.addAttribute("glist",goodsList);
        return "daqi/index";
    }

    @RequestMapping("/infor")
    public  String  infor(int gid,Model model){
//        根据id号获得商品的详情
        Goods goods=goodsService.getGoodsById(gid);
        model.addAttribute("good",goods);
        //商品详情页
        return "infor";

    }
}
